package com.hicampus.portlet.verifycontact;

import java.io.Serializable;

import com.hicampus.common.service.RegionLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.Country;
import com.liferay.portal.service.CountryServiceUtil;

public class GeoLocation implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public GeoLocation(String data) {
		String[] tokens = data.split(StringPool.COMMA);
		
		setCountryCode(tokens[0]);
		setRegionCode(tokens[1]);
		setCity(tokens[2]);
		setLatitude(tokens[3]);
		setLongitude(tokens[4]);
		try {
			this.region = RegionLocalServiceUtil.getRegionNameByCC_RC(tokens[0], tokens[1]);
		} catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public long getCountryId() {
		return countryId;
	}
	public void setCountryId(long countryId) {
		this.countryId = countryId;
	}
	public int getRegionId() {
		return regionId;
	}
	public void setRegionId(int regionId) {
		this.regionId = regionId;
	}
	public int getCityId() {
		return cityId;
	}
	public void setCityId(int cityId) {
		this.cityId = cityId;
	}
	
	public String getCountryCode() {
		return countryCode;
	}
	public void setCountryCode(String countryCode) {
		this.countryCode = countryCode;
		
		try {
			Country _country = CountryServiceUtil.getCountryByA2(countryCode);
			this.countryId = _country.getCountryId();
			this.country = _country.getName();
			this.idd = _country.getIdd();
			
		} catch (PortalException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public String getRegionCode() {
		return regionCode;
	}
	public void setRegionCode(String regionCode) {
		this.regionCode = regionCode;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}	
	
	public String getLatitude() {
		return latitude;
	}
	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}
	public String getLongitude() {
		return longitude;
	}
	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}
	
	public String getIdd() {
		return idd;
	}

	private long countryId;
	private int regionId;
	private int cityId;
	
	private String countryCode;
	private String regionCode;
	private String city;
	private String latitude;
	private String longitude;
	
	private String region;
	private String country;
	private String idd;
	
	public String getFormattedText() {
		StringBuilder sb = new StringBuilder();
		
		sb.append(this.city).append(", ");
		sb.append(this.region).append(", ");
		sb.append(this.country).append(".");
		
		return sb.toString();
	}
}
